package com.campus.activity.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.campus.activity.entity.Activity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 活动Mapper接口
 * 
 * @author System
 * @since 2024
 */
@Mapper
public interface ActivityMapper extends BaseMapper<Activity> {

    /**
     * 根据活动类型查询活动列表
     * 
     * @param activityType 活动类型
     * @return 活动列表
     */
    @Select("SELECT * FROM activity WHERE activity_type = #{activityType} AND deleted = 0")
    List<Activity> selectByActivityType(@Param("activityType") String activityType);

    /**
     * 根据时间范围查询活动列表
     * 
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 活动列表
     */
    @Select("SELECT * FROM activity WHERE start_time >= #{startTime} AND end_time <= #{endTime} AND deleted = 0")
    List<Activity> selectByTimeRange(@Param("startTime") LocalDateTime startTime, 
                                   @Param("endTime") LocalDateTime endTime);

    /**
     * 根据地点查询活动列表
     * 
     * @param location 活动地点
     * @return 活动列表
     */
    @Select("SELECT * FROM activity WHERE location LIKE CONCAT('%', #{location}, '%') AND deleted = 0")
    List<Activity> selectByLocation(@Param("location") String location);

    /**
     * 查询即将截止报名的活动
     * 
     * @param currentTime 当前时间
     * @return 活动列表
     */
    @Select("SELECT * FROM activity WHERE registration_deadline > #{currentTime} AND deleted = 0 ORDER BY registration_deadline ASC")
    List<Activity> selectUpcomingDeadline(@Param("currentTime") LocalDateTime currentTime);

    /**
     * 根据组织者ID查询活动列表
     * 
     * @param organizerId 组织者ID
     * @return 活动列表
     */
    @Select("SELECT * FROM activity WHERE organizer_id = #{organizerId} AND deleted = 0")
    List<Activity> selectByOrganizerId(@Param("organizerId") Integer organizerId);
}